package club.caihappy.store.controller;

import club.caihappy.store.entity.Address;
import club.caihappy.store.entity.Product;
import club.caihappy.store.service.IProductService;
import club.caihappy.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by DELL on 2022/3/22
 **/
@RestController
@RequestMapping("products")
public class ProductController extends BaseController {

    @Autowired
    private IProductService productService;

    @RequestMapping("hot_list")
    public JsonResult<List<Product>> getHotList() {
        List<Product> products = productService.findHotList();
        return new JsonResult<>(OK, products);
    }

    @RequestMapping("details/{id}")
    public JsonResult<Product> getById(@PathVariable("id") Integer id) {
        Product product = productService.getProduct(id);
        return new JsonResult<>(OK, product);
    }
}
